import Taro, { Component } from '@tarojs/taro'
import { Provider } from '@tarojs/redux'
import VConsole from 'vconsole'
import Index from './pages/index'

import configStore from './store'
import './app.scss'

// const vConsole = new VConsole()

const store = configStore()

class App extends Component {

  config = {
    pages: [
      'pages/index/index',
      'pages/main/index',
      'pages/myorder/index',
      'pages/order/index',
      'pages/order/goods/index',
      'pages/order/increment/index',
      'pages/detail/index',
      'pages/addressbook/index',
      'pages/addresscreate/index',
      'pages/addressselector/index',
    ],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: 'WeChat',
      navigationBarTextStyle: 'black'
    }
  }

  componentDidMount () {
    if (typeof WeixinJSBridge === 'undefined') {
      if (document.addEventListener) {
        document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady, false);
      } else if (document.attachEvent) {
        document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady);
        document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady);
      }
    } else {
      this.onBridgeReady();
    }
  }

  onBridgeReady = () => {
    console.log('onBridgeReady')
  }

  componentDidHide () {}

  componentDidCatchError () {}

  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render () {
    return (
      <Provider store={store}>
        <Index />
      </Provider>
    )
  }
}

Taro.render(<App />, document.getElementById('app'))
